package com.cxy.controller.admin;

import com.cxy.dto.AccessDTO;
import com.cxy.dto.AccessPageDTO;
import com.cxy.result.PageResult;
import com.cxy.result.Result;
import com.cxy.service.AccessService;
import com.cxy.vo.AccessVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(tags = "评议项管理业务功能")
@RestController
@RequestMapping("/access")
@Slf4j
/**
 * 评议项管理业务功能
 */
public class AccessController {
    @Autowired
    private AccessService accessService;

    /**
     * 评议项管理分页查询
     */
    @ApiOperation("评议项管理分页查询")
    @GetMapping("/page")
    public Result<PageResult> page( AccessPageDTO accessPageDTO){
        log.info("分页查询:{}",accessPageDTO);
        PageResult pageResult = accessService.page(accessPageDTO);
        return Result.success(pageResult);
    }
    /**
     * 新增评议项
     */
    @ApiOperation("新增评议项")
    @PostMapping("/insert")
    public Result insert(@RequestBody AccessDTO accessDTO){
        log.info("新增评议项");
        accessService.insert(accessDTO);
        return Result.success();
    }
    /**
     * 修改评议项
     */
    @ApiOperation("修改评议项")
    @PutMapping("/update")
    public Result update(@RequestBody AccessDTO accessDTO){
        log.info("修改评议项：{}",accessDTO);
        accessService.update(accessDTO);
        return Result.success();
    }
    /**
     * 根据id查询评议项信息
     */
    @ApiOperation("根据id查询评议项信息")
    @RequestMapping("/select/{id}")
    public Result<AccessVO> getById(@PathVariable Long id){
        log.info("查询的id:{}",id);
       AccessVO accessVO = accessService.getById(id);
       return Result.success(accessVO);
    }
    /**
     * 删除评议项
     */
    //@RequestParam绑定参数关系
    @ApiOperation("删除评议项")
    @DeleteMapping("/delete")
    public Result delete(@RequestParam List<Long>ids){
        log.info("需要删除评议项的id:{}",ids);
        accessService.delete(ids);
        return Result.success();
    }
}
